<%@ page contentType="text/html;charset=utf-8"%>
<%@ page
	import="java.io.*, java.sql.*, java.util.*, java.text.*, napal.*, util.*, napal.*"%>
<%@ page import="org.apache.ibatis.*"%>
<%@ page import="java.util.Date"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="my" %>
<%
	request.setCharacterEncoding("utf-8");
String m = (String)session.getAttribute("managerID");
int currentPage = 1, pageSize = 10;
String spg = request.getParameter("pg");
if (spg != null) currentPage = Integer.parseInt(spg);

	if(m==null){ %>
<script language=javascript>
			self.window.alert("권한이 없습니다.");
			location.href="Main.jsp?";
		</script>
<%}
	
%>


<%@ include file="./Header.jsp"%></td>
</TR>
<TR HEIGHT="100">
	<TD><a href="giguan.jsp" class="btn btn-link btn-small">기자재관리<br></a><br>
	<br>
	<a href="./Model.jsp" class="btn btn-inverse" style="width: 90">모델관리</a>
			<a href="./EquipmentEnroll.jsp" class="btn btn-inverse"
				style="width: 110">기자재등록</a>
		<table class="table">

			<%
				String selectedCategory = request.getParameter("selectedCategory");
				String name = request.getParameter("searchname");
				if (name == null) {
					name = "";
				}
				int j = 0;
			%>
			<input type="hidden" name="category" value="<%=selectedCategory%>" />

			<form method="post">

<p align="right">
				<select name="selectedCategory">
					<OPTION VALUE='카테고리선택'>카테고리선택</OPTION>

					<%
						for (Model g : RentalHome.category()) {
					%>
					<OPTION VALUE="<%=g.get카테고리명()%>"
						<%=g.get카테고리명().equals(selectedCategory) ? "selected"
						: ""%>><%=g.get카테고리명()%></OPTION>

					<%
						}
					%>

				</SELECT><input type="text" name="searchname" placeholder="관리번호" value=<%=name %>> <input
					 name="cmd" type="submit"
					class="btn btn-inverse" value="search"></p>
			</form>
		</table> <%
 	if (request.getParameter("cmd") == null) {
 %>
		<table class="table">
			<TR>
				<TD>No.</TD>
				<TD>기자재관리번호</TD>
				<TD>모델명</TD>
				<TD>기자재상태</TD>
				<TD>보관사용처</TD>
			</TR>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
		</table> <%
 	}
 	else	if ("search".equals(request.getParameter("cmd"))) {
 %> <%
 	if (name == "") {
 %>
		<table class="table">
			<TR>
				<TD>No.</TD>
				<TD>기자재관리번호</TD>
				<TD>모델명</TD>
				<TD>기자재상태</TD>
				<TD>보관사용처</TD>

			</TR>
			<%
				//for (EM g : RentalHome.categoryview(selectedCategory)) {
					 for (EM g : RentalHome.selectPageGiguan(currentPage, pageSize, selectedCategory)) { 
							j = j + 1;
			%>

			<TR class="selectableItem"
				onclick="document.location='./EquipmentDetail_m.jsp?str_aid=<%=g.get기자재번호()%>'">
				<TD><%=j%></TD>
				<TD><%=g.get기자재관리번호()%></TD>
				<TD><%=g.get모델명()%></TD>
				<TD><%=g.get기자재상태()%></TD>
				<TD><%=g.get보관사용처()%></TD>
			</TR>
			<%
				}
			%>

		</table><p align="center">	<my:pager3 pageSize="<%= pageSize %>" recordCount="<%= RentalHome.selectCountGiguan(selectedCategory) %>" selectedCategory="<%=selectedCategory %>"/></p> <%
 	}

 		else {
 %>
		<table class="table">
			<TR>
				<TD>No.</TD>
				<Td>기자재관리번호</TD>
				<TD>모델명</TD>
				<TD>기자재상태</TD>
				<TD>보관사용처</TD>
			</TR>
			<%
				for (EM i : RentalHome.search(name)) {
							j = j + 1;
			%>

			<TR class="selectableItem"
				onclick="document.location='./EquipmentDetail_m.jsp?str_aid=<%=i.get기자재번호()%>'">
				<TD><%=j%></TD>
				<TD><%=i.get기자재관리번호()%></TD>
				<TD><%=i.get모델명()%></TD>
				<TD><%=i.get기자재상태()%></TD>
				<TD><%=i.get보관사용처()%></TD>
			</TR>
			<%
				}
			%>
			<a href="./Model.jsp" class="btn btn-inverse" style="width: 90">모델관리</a>
			<a href="./EquipmentEnroll.jsp" class="btn btn-inverse"
				style="width: 110">기자재등록</a>


		</table>
		
		 <input type="hidden" name="category" value="<%=selectedCategory%>" />
		<%
			}
			}
		%></td>
</TR>

<TR HEIGHT="50">
	<TD><%@ include file="./bottom.jsp"%></TD>
</TR>
</TABLE>

</body>
</html>